package cn.check;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.SQLException;

import cn.dbconnection.DBConnection;

public class UserNameCheck {
	public boolean check(String userName) {
		Connection conn = DBConnection.getConnection();
		PreparedStatement pstmt = null;
		String sql = "SELECT count() FROM is_member WHERE trim(user_id)=?";
		try {
			pstmt = conn.prepareStatement(sql);
			pstmt.setString(1, userName);
			if (pstmt.getMaxRows() == 0) {
				System.out.println(pstmt.getMaxRows());
				return true;
			} else {
				System.out.println(pstmt.getMaxRows() + "in else");
				return false;
			}
		} catch (SQLException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		} finally {
			try {
				if (null != pstmt) {
					pstmt.close();
				}
				if (null != conn) {
					conn.close();
				}
			} catch (SQLException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}

		}
		return false;
	}
}
